package com.ztgf.commodity.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.commodity.models.service.IShieldPartsService;
import com.ztgf.commodity.models.bo.ShieldPartsBO;
import com.ztgf.commodity.models.dto.ShieldPartsDTO;

/**
 * 盾构部位表控制器
 *
 * @author chenyu.wang
 * @Date 2020-06-02 15:11:05
 */

@RestController
@RequestMapping("/api/shieldParts")
@Slf4j
@Api(value = "ShieldPartsApiController", tags = "盾构部位表Api接口")
public class ShieldPartsApiController {

    @DubboReference
    private IShieldPartsService shieldPartsService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找", notes = "根据id查找")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "Long")
    public Result<ShieldPartsDTO> get(Long id) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        ShieldPartsDTO dto = shieldPartsService.selectById(id);
        return new Result<>(dto);
    }

    @PostMapping("/queryPageList")
    @ApiOperation(value = "盾构部位表列表", notes = "盾构部位表列表")
    public Result<Page<ShieldPartsDTO>> queryPageList(ShieldPartsBO bo) {
        Wrapper<ShieldPartsDTO> wrapper = new EntityWrapper<>();
        if (bo.getStatus() != null) {
            wrapper.eq("status", bo.getStatus());
        }
        if (bo.getStartDate() != null) {
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null) {
            wrapper.le("create_time", bo.getEndDate());
        }
        Page<ShieldPartsDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = shieldPartsService.selectPage(page, wrapper);
        return new Result<>(page);
    }
}
